package com.usian.skill.controller;

import com.usian.skill.common.CodeMsg;
import com.usian.skill.common.Result;
import com.usian.skill.pojo.OrderInfo;
import com.usian.skill.pojo.SkillUser;
import com.usian.skill.service.GoodsService;
import com.usian.skill.service.OrderInfoService;
import com.usian.skill.service.SkillUserService;
import com.usian.skill.vo.GoodsVo;
import com.usian.skill.vo.OrderDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;


@Controller
@RequestMapping("/order")
public class OrderController {

	@Autowired
	SkillUserService userService;

	
	@Autowired
	OrderInfoService orderService;
	
	@Autowired
	GoodsService goodsService;
	
    @RequestMapping("/detail")
    @ResponseBody
    public Result<OrderDetailVo> info(Model model, HttpSession session,
									  @RequestParam("orderId") long orderId) {
    	//获取登录用户信息
		String userId = (String) session.getAttribute("userId");
		if (userId==null){
			return Result.error(CodeMsg.SESSION_ERROR);
		}
		//获取订单信息
		OrderInfo order = orderService.getById(orderId);
		if (order==null){
			return Result.error(CodeMsg.ORDER_NOT_EXIST);
		}
		//获取商品信息
		Long goodsId = order.getGoodsId();
		GoodsVo goodsVo = goodsService.getGoodsVoByGoodsId(goodsId);
		//封装
		OrderDetailVo vo = new OrderDetailVo();
		vo.setOrder(order);
		vo.setGoods(goodsVo);
		return Result.success(vo);
    }
    
}
